<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Review Rating Synthesis
 * @version 	1.0
 * @author Nguyen Dinh Nhat<nguyendnhat@gmail.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

if (!defined('_PS_VERSION_')) {
    exit;
}
include(_PS_MODULE_DIR_."zgallery/classes/ZgalleryConfig.php");
include_once(_PS_MODULE_DIR_."zgallery/ZadminGallery.php");
class zgallery extends zgalleryConfig {
	const INSTALL_SQL_FILE = 'sql/install.sql';
	const UNINSTALL_SQL_FILE = 'sql/uninstall.sql';
	
	/**
     * Sole constructor
    */
	
	public function __construct()
	{
		global $smarty ;
		$this->name='zgallery';
		$this->version='1.0.0';
//		$this->tab = 'front_office_features';		
		parent::__construct();
		$this->displayName=$this->l('Gallery');
		$this->description=$this->l('Allow to manage albums and photos');
        $this->confirmUninstall = $this->l('Uninstall Gallery?');
	}
	
	/**
     * Intall module. Creates module tables and adds module configuration
     * to configuration table.
     * @return boolean true if this module installs successfully, false
     * otherwise
     */
    public function install() {
       	
        if (!$this->initConfiguration())
        	return false;
        
		if (!$this->_addAdminTab(array('parentClassName' 	=> 'AdminCustomers',
									   'childClassName' 	=> 'ZadminGallery',
									   'childTabName' 		=> 'Gallery')))
			return false;
        
		if (!$this->_sql(self::INSTALL_SQL_FILE))
			return false;
		
		if (!parent::install())
			return false;
			
		if (!$this->registerHook('home')
       		OR !$this->registerHook('rightColumn')
       	)
        	return false;
       	
        return true;
    }

    /**
     * Uninstall module.
     * Drops module tables from the DB and removes module configuration from
     * the configuration table.
     * @return boolean true if this module uninstalls successfully, false
     * otherwise
     */
    
	public function uninstall(){
		if (!$this->_sql(self::UNINSTALL_SQL_FILE))
			return false;

		if (!$this->_removeAdminTab('ZadminGallery'))
			return false;
	
		if (!parent::uninstall())
			return false;
			
		if (!$this->destroyConfiguration())
			return false;
			
		return true;
	}	

	public function hookRightColumn ($params) {
		global $smarty,$cookie;
		return ($this->display(__FILE__,'views/hookRightColumn.tpl'));
	}
}

